
/* 

Paper: Gentrification and pioneer businesses 
Authors: Behrens, Boulam, Martin, Mayneris 

Name dofile: identify_gentri_blocks.do  
Version: 15 nov. 2021 

Outputs: 
- blocks_mobility_income_edu.dta 
- blocks_gentrified.dta 
- gentri_dum_id_conc.dta 

Inputs: 
- id_conc_database.dta (from create_db_concordedblocks.do)

*/ 



// reshape the data 
use id_conc_database.dta, clear
tsset id_conc t
g sh_edu=edu_college_block/pop if pop!=. 
rename year_census year
rename percap_income_block pc
keep id_conc pc sh_edu year pop dis_ws
drop if pop<8 
reshape wide sh_edu pc pop, i(id_conc dis_ws) j(year)  

// compute blocks decile changes by year 
foreach i in 1990 2000 2010{
local z 10 // # of bins 
xtile pctile_pc`i'=pc`i', n(`z')
xtile pctile_sh_edu`i'=sh_edu`i', n(`z')
}

foreach i in sh_edu pc {
g change_decile_`i'_9000=pctile_`i'2000 - pctile_`i'1990
g change_decile_`i'_9010=pctile_`i'2010 - pctile_`i'1990
g change_decile_`i'_0010=pctile_`i'2010 - pctile_`i'2000
}

foreach i in 9000 9010 0010 {
label var change_decile_sh_edu_`i' "Decile change, share of educated, period `i' "
label var change_decile_pc_`i' "Decile change, per capita income, period `i' "
}

foreach i in 1990 2000 2010{
label var pop`i' "Population, year `i'"
label var sh_edu`i' "Share of college educated, year `i'"
label var pc`i' "Per capita income, year `i'"
}

save blocks_mobility_income_edu,  replace // data used in GIS 

// create gentrification dummy 
use blocks_mobility_income_edu, clear 
keep if change_decile_sh_edu_9000 !=. 
keep if change_decile_pc_9000 !=. 
g gentri_9000=(pctile_pc1990<6 & change_decile_pc_9000>2 & change_decile_pc_9000!=. ) & (change_decile_sh_edu_9000>0) 
g gentri_0010=(pctile_pc2000<6 & change_decile_pc_0010>2  & change_decile_pc_0010!=.) & (change_decile_sh_edu_0010>0) 
g yes=gentri_9000+ gentri_0010
drop if yes==0
keep id_conc gentri_9000 gentri_0010 pctile_pc1990 pctile_pc2000 pop*
compress 
sort id_conc 
save blocks_gentrified, replace  
*export delimited blocks_gentrified.csv,  replace // data used in GIS 

// identify poor blocks (that could gentrify)
use blocks_mobility_income_edu, clear 
g poor_9000=(pctile_pc1990<6   )  
g poor_0010=(pctile_pc2000<6 )   
g yes=poor_9000+ poor_0010
drop if yes==0
keep id_conc poor_9000 poor_0010 pctile_pc1990 pctile_pc2000
sort id_conc
save blocks_couldgentrify, replace 


// merge with id_conc database 
use blocks_gentrified.dta, clear
duplicates drop id_conc, force
g yes1990=(gentri_9000==1 )  
g yes2000= (gentri_0010==1 )  
keep if yes1990==1|yes2000==1
keep id_conc yes1990 yes2000
rename yes1990 gentri1990
rename yes2000 gentri2000
save  temp, replace 

use  id_conc_database.dta, clear
duplicates drop id_conc, force
merge 1:1 id_conc using temp
replace gentri1990=0 if _m==1
replace gentri2000=0 if _m==1
keep id_conc gentri1990 gentri2000 intptlat intptlon
save gentri_dum_id_conc.dta ,  replace


